﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsAPICodePack.Taskbar;

namespace Nizm0.QOT.Panels
{
    public partial class ErrorLog : ToolWindow, Library.Objects.IErrorLog
    {
        public ErrorLog()
            : base()
        {
            InitializeComponent();
            ImageList imagelist = new ImageList();
            imagelist.Images.Add("Corect", global::Nizm0.QOT.Properties.Resources.Corect);
            imagelist.Images.Add("Wrong", global::Nizm0.QOT.Properties.Resources.Wrong);
            imagelist.Images.Add("Warning", global::Nizm0.QOT.Properties.Resources.Warning);
            listView1.SmallImageList = imagelist;
        }

        public void AddError(IVerificationLogItem VerificationLogItem)
        {
            try
            {
                ListViewItem item = new ListViewItem(VerificationLogItem.Source.ToString(), listView1.SmallImageList.Images.IndexOfKey(ImagesType.Wrong.ToString()));
                //listView1.Items.Add(log, log, listView1.SmallImageList.Images.IndexOfKey(i.ToString()));
                ListViewItem.ListViewSubItem listSubItem1 = new ListViewItem.ListViewSubItem(item, VerificationLogItem.ex.Message + '\n' + VerificationLogItem.ex.ToString());
                item.SubItems.Add(listSubItem1);
                if (listView1.InvokeRequired)
                {
                    lock (listView1)
                        listView1.Invoke((MethodInvoker)delegate
                        {
                            listView1.Items.Add(item);
                        });
                }
                else
                    listView1.Items.Add(item);

                if (TaskbarManager.Instance != null && TaskbarManager.IsPlatformSupported)
                    TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Error);
            }
            catch
            {
            }
        }

        #region IAplicationLog Members

        void Library.Objects.IErrorLog.ErrorLog(object sender, Exception ex)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public interface IVerificationLogItem
    {
        QOT.Panels.ImagesType ImageType { get; set; }
        Exception ex { get; set; }
        object Source { get; set; }
    }

    public class VerificationLogItem : IVerificationLogItem
    {
        public VerificationLogItem(Exception ex, object source)
        {
            this.ex = ex;
            Source = source;
        }

        #region iVerificationLogItem Members

        public ImagesType ImageType
        {
            get;
            set;
        }

        public Exception ex
        {
            get;
            set;
        }

        public object Source
        {
            get;
            set;
        }

        #endregion
    }
}
